extends VehicleBody3D

@onready var front_left = $FrontLeft
@onready var front_right = $FrontRight
@onready var rear_left = $RearLeft
@onready var rear_right = $RearRight

const MAX_STEER = 0.3
const ENGINE_POWER = 100
const MOVE_TURN_POWER = 250
const TURN_POWER = 400
	
func _process(delta):
	
	engine_force = Input.get_axis("move_backward", "move_forward") * ENGINE_POWER
	
	if Input.is_action_pressed("turn_left"):
		if Input.is_action_pressed("move_forward"):
			rear_left.engine_force = -MOVE_TURN_POWER/2
			front_left.engine_force = -MOVE_TURN_POWER/2
			rear_right.engine_force = MOVE_TURN_POWER
			front_right.engine_force = MOVE_TURN_POWER
		elif Input.is_action_pressed("move_backward"):
			rear_left.engine_force = MOVE_TURN_POWER/2
			front_left.engine_force = MOVE_TURN_POWER/2
			rear_right.engine_force = -MOVE_TURN_POWER
			front_right.engine_force = -MOVE_TURN_POWER
		else:
			rear_left.engine_force = -TURN_POWER
			front_left.engine_force = -TURN_POWER
			rear_right.engine_force = TURN_POWER
			front_right.engine_force = TURN_POWER
		
	if Input.is_action_pressed("turn_right"):
		if Input.is_action_pressed("move_forward"):
			rear_left.engine_force = MOVE_TURN_POWER
			front_left.engine_force = MOVE_TURN_POWER
			rear_right.engine_force = -MOVE_TURN_POWER/2
			front_right.engine_force = -MOVE_TURN_POWER/2
		elif Input.is_action_pressed("move_backward"):
			rear_left.engine_force = -MOVE_TURN_POWER
			front_left.engine_force = -MOVE_TURN_POWER
			rear_right.engine_force = MOVE_TURN_POWER/2
			front_right.engine_force = MOVE_TURN_POWER/2
		else:
			rear_left.engine_force = TURN_POWER
			front_left.engine_force = TURN_POWER
			rear_right.engine_force = -TURN_POWER
			front_right.engine_force = -TURN_POWER
